//
//  Loadviewcontroller.m
//  ZYShang
//
//  Created by wangguangming on 15/7/24.
//  Copyright © 2015年 Amber. All rights reserved.
//

#import "Loadviewcontroller.h"
#import "Base.h"
#import "Loadsingle.h"
@interface Loadviewcontroller ()
@property(nonatomic,strong)UITextField *userName;
@property(nonatomic,strong)UITextField *passWord;
@property(nonatomic,strong)UIButton *loadButton;
@end

@implementation Loadviewcontroller
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) 
        {
        
        }
    return self;
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSString *documents=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
    NSString *file1=[documents stringByAppendingString:@"/usera.plist"];
    
    NSDictionary *account=[NSDictionary dictionaryWithContentsOfFile:file1];
    
    self.userName.text=[account valueForKey:@"account"];
        // NSLog(@"%@",account);
    
    NSString *file2=[documents stringByAppendingString:@"/userp.plist"];
    
    NSDictionary *password=[NSDictionary dictionaryWithContentsOfFile:file2];
        // NSLog(@"%@",password);
    self.passWord.text=[password valueForKey:@"password"];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor colorWithRed:242/256.0 green:242/256.0 blue:242/256.0 alpha:1];
    self.title=@"在路上";
    self.userName=[[UITextField alloc] init];
    self.userName.frame=CGRectMake(10, 64, WIDTH-20, 40);
    self.userName.placeholder=@"账号";
    self.userName.layer.borderColor=[[UIColor grayColor] CGColor];
    self.userName.layer.borderWidth=1.0;
    self.userName.layer.cornerRadius=6;
    self.userName.textColor=[UIColor grayColor];
    [self.view addSubview:self.userName];
    
    
    self.passWord=[[UITextField alloc] init];
    self.passWord.frame=CGRectMake(10, 129, WIDTH-20, 40);
    self.passWord.placeholder=@"密码";
    self.passWord.layer.borderWidth=1.0;
    self.passWord.layer.borderColor=[[UIColor grayColor] CGColor];
    self.passWord.secureTextEntry=YES;
    self.passWord.layer.cornerRadius=6;
     self.passWord.textColor=[UIColor grayColor];
    [self.view addSubview:self.passWord];
    
    self.loadButton=[[UIButton alloc] init];
    self.loadButton.frame=CGRectMake(WIDTH/2-80, 194, 160, 40);
    [self.loadButton setTitle:@"登陆" forState:UIControlStateNormal];
    self.loadButton.layer.cornerRadius=4;
    self.loadButton.backgroundColor=[UIColor redColor];
    [self.loadButton addTarget:self action:@selector(loadAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.loadButton];
    
//    UIButton *button = [[UIButton alloc] init];
//    button.frame=CGRectMake(WIDTH/2-30, 260, 60, 40);
//    [button setTitle:@"登出" forState:UIControlStateNormal];
//    
//    button.backgroundColor=[UIColor redColor];
//    [button addTarget:self action:@selector(loadAction1) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:button];
}
-(void)loadAction1{
    [[Loadsingle single] loagout];
}
-(void)loadAction
{
    
    
    [Loadsingle single].account=self.userName.text;
    [Loadsingle single].password=self.passWord.text;
    [[Loadsingle single] login];
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
    
    
    
    [nc addObserver:self
           selector:@selector(handleColorChange)
               name:@"do"
             object:nil];

    
}
-(void)handleColorChange {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


@end
